<template>
  <div class="page page__syssetting_dialog clearBoth">
    <div class="btns">
      <span
        @click="submit()"
        class="btn submit"
      >
        <i class="fa fa-save" />
        保存
      </span>
      <span
        @click="hideDialog"
        class="btn"
      >
        <i class="fa fa-mail-reply" />
        返回
      </span>
    </div>
    <div
      :style="{ height: bodyHeight }"
      class="page_content clearBoth"
    >
      <div class="sys_nav left">
        <div
          v-for="(item, index) in navlist"
          :key="index"
          @click="changeNav(item)"
          :class="`nav_items pointer ${active.value===item.value ? 'active' : ''}`"
        >
          {{ item.label }}
        </div>
      </div>
      <div class="sys_content right">
        <div class="scroll_wrp">
          <div class="scroll">
            <div class="sys_items">
              <p
                @click="showHide('jmsj')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.jmsj}"
                  class="icon jeicon jeicon-play"
                />
                页面设置
                <span style="margin-left: 20px;font-size: 12px;">
                  注意: 本表单信息记录在数据表JE_CORE_SETTING中。
                </span>
              </p>
              <div class="content_wrp">
                <jmsj
                  id="jmsj"
                  ref="jmsj"
                  v-if="showData.jmsj"
                  :formdata="formdata"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('yxsz')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.yxsz}"
                  class="icon jeicon jeicon-play"
                />
                运行设置
              </p>
              <div class="content_wrp">
                <yxsz
                  id="yxsz"
                  ref="yxsz"
                  v-if="showData.yxsz"
                  :formdata="formdata"
                  :dictlist="dictlist"
                  @showHolderDialog="showHolderDialog"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('dlfw')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.dlfw}"
                  class="icon jeicon jeicon-play"
                />
                登录服务
              </p>
              <div class="content_wrp">
                <dlfw
                  id="dlfw"
                  ref="dlfw"
                  v-if="showData.dlfw"
                  :formdata="formdata"
                  :dictlist="dictlist"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('dsffw')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.dsffw}"
                  class="icon jeicon jeicon-play"
                />
                第三方服务
              </p>
              <div class="content_wrp">
                <dsffw
                  id="dsffw"
                  ref="dsffw"
                  v-if="showData.dsffw"
                  :formdata="formdata"
                  :dictlist="dictlist"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('xxfw')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.xxfw}"
                  class="icon jeicon jeicon-play"
                />
                消息服务
              </p>
              <div class="content_wrp">
                <xxfw
                  id="xxfw"
                  ref="xxfw"
                  v-if="showData.xxfw"
                  :formdata="formdata"
                  :dictlist="dictlist"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('wdgl')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.wdgl}"
                  class="icon jeicon jeicon-play"
                />
                文档管理
              </p>
              <div class="content_wrp">
                <wdgl
                  id="wdgl"
                  ref="wdgl"
                  v-if="showData.wdgl"
                  :formdata="formdata"
                  :dictlist="dictlist"
                />
              </div>
            </div>
            <div class="sys_items">
              <p
                @click="showHide('gzfw')"
                class="modal_title"
              >
                <i
                  :class="{'showAll': showData.gzfw}"
                  class="icon jeicon jeicon-play"
                />
                工作服务
              </p>
              <div class="content_wrp">
                <gzfw
                  id="gzfw"
                  ref="gzfw"
                  v-if="showData.gzfw"
                  :formdata="formdata"
                  :dictlist="dictlist"
                />
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-dialog
        :visible.sync="holderDialog.show"
        :modal-append-to-body="false"
        :show-close="false"
        class="holder_dialog"
      >
        <div
          v-html="holderDialog.data"
          class="dialog_content"
        />
        <!-- <div class="dialog_content">

        </div> -->
        <div class="btn_group">
          <span @click="holderDialog.show=!holderDialog.show">关 闭</span>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import jmsj from '../../components/jmsj';// 界面设置
import yxsz from '../../components/yxsz';// 运行设置
import dlfw from '../../components/dlfw';// 登录服务
import dsffw from '../../components/dsffw';// 第三方服务
import xxfw from '../../components/xxfw';// 消息服务
import wdgl from '../../components/wdgl';// 文档管理
import gzfw from '../../components/gzfw';// 工作服务
import holder from '../../form.js';

export default {
  name: 'IndexForm',
  components: {
    jmsj, yxsz, dlfw, dsffw, xxfw, wdgl, gzfw,
  },
  props: {
    navlist: {
      type: Array,
      default: () => [],
    },
    dictlist: {
      type: Array,
      default: () => [],
    },
    active: {
      type: Object,
      default: () => {},
    },
    formdata: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      showData: {
        jmsj: true,
        yxsz: true,
        dlfw: true,
        dsffw: true,
        xxfw: true,
        wdgl: true,
        gzfw: true,
      },
      holderDialog: {
        show: false,
        data: {},
      },
    };
  },
  computed: {
    bodyHeight() {
      return `${document.body.clientHeight - 44}px`;
    },
  },
  watch: {
    navlist: {
      handler(nv) {
        if (nv) {
          this.$nextTick(() => {
            nv.forEach((item) => {
              if (document.getElementById(item.value)) {
                item.top = document.getElementById(item.value).offsetTop - 94;
              }
            });
          });
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {},
  mounted() {
    const scrollDiv = document.querySelectorAll('.scroll_wrp')[0];
    scrollDiv.addEventListener('scroll', () => {
      this.$nextTick(() => {
        for (let i = 0; i < this.navlist.length; i++) {
          if (this.navlist[i].top < scrollDiv.scrollTop && this.navlist[i + 1].top >= scrollDiv.scrollTop) {
            this.active = this.navlist[i];
          }
        }
      });
    });
  },
  methods: {
    changeNav(item) {
      this.$nextTick(() => {
        // this.active = item;
        this.$set(this, 'active', item);
        document.querySelectorAll('.scroll_wrp')[0].scrollTop = item.top + 1;
      });
    },
    hideDialog() {
      this.$emit('hideDialog');
    },
    submit() {
      this.$emit('submit');
    },
    showHide(code) {
      this.showData[code] = !this.showData[code];
      this.$nextTick(() => {
        this.navlist.forEach((item) => {
          if (document.getElementById(item.value)) {
            item.top = document.getElementById(item.value).offsetTop - 94;
          }
        });
      });
    },
    showHolderDialog(code) {
      this.holderDialog.show = !this.holderDialog.show;
      this.holderDialog.data = holder.holderText()[code];
    },
  },
};
</script>

<style lang="scss" scoped>
  .page__syssetting_dialog {
    .btns {
      height: 44px;
      line-height: 44px;
      padding: 0 15px;
      border-bottom: 1px solid #dddddd;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      .btn {
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        background: #f4f4f4;
        border: 1px solid #dddddd;
        color: #444444;
        font-size: 12px;
        &:hover {
          background-color: #e7e7e7;
          border-color: #adadad;
        }
        &.submit {
          border: 1px solid #386bd0;
          color: #ffffff;
          background: #386bd0;
          &:hover {
            color: #ffffff;
            background-color: #1a4c9c;
            border-color: #1a4c9c;
          }
        }
        &:not(:first-child) {
          margin-left: 15px;
        }
      }
    }
    .page_content {
      width: 1200px;
      margin: 44px auto 0;
      .sys_nav {
        width: 10%;
        text-align: right;
        border-right: 1px solid #f3f3f3;
        // height: 100%;
        margin-top: 20px;
        .nav_items {
          padding: 6px 15px;
          position: relative;
          margin: 2px 0;
          border-right: 4px solid transparent;
          &.active {
            color: #386bd0;
            border-right-color: #386bd0;
          }
        }
      }
      .sys_content {
        width: 90%;
        padding-left: 2%;
        height: 100%;
        overflow: hidden;
        // margin-top: 20px;
        .scroll_wrp {
          width: 101%;
          padding-right: 1%;
          height: 100%;
          overflow-y: auto;
          .scroll {
            padding: 20px 1% 20px 0;
            min-height: 100%;
            .sys_items {
              &:not(:first-child) {
                margin-top: 20px;
              }
              .modal_title {
                height: 40px;
                line-height: 40px;
                padding: 0 20px;
                font-size: 18px;
                position: relative;
                font-weight: bold;
                cursor: pointer;
                .icon {
                  position: absolute;
                  left: 5px;
                  font-size: 12px;
                  transform: rotate(90deg);
                  transition: all 300ms;
                  &.showAll {
                    transform: rotate(-90deg);
                  }
                }
              }
              .content_wrp {
                margin-top: 10px;
              }
            }
          }
        }
      }
    }
  }
</style>
<style lang="scss" scoped>
  .left {
    float: left;
  }
  .right {
    float: right;
  }
  .clearBoth {
    &:after {
      content: '';
      clear: both;
      display: table;
    }
  }
  .pointer {
    cursor: pointer;
  }
</style>

<style lang="scss">
  .sys_setting_formdata_style {
    .item {
      padding-left: 20px;
      &:not(:first-child) {
        margin-top: 20px;
      }
      .title {
        font-size: 13px;
        color: #3F3F3F;
        .jeicon-question-circle {
          font-size: 14px;
          color: #999999;
          cursor: pointer;
          &:hover {
            color: #4D7ED5;
          }
        }
      }
      .holder {
        font-size: 10px;
        color: #999999;
        padding-left: 5px;
        margin-top: 8px;
      }
      .el-checkbox+.el-checkbox {
        margin-left: 16px;
      }
      .el-textarea {
        margin-top: 5px;
      }
      .el-input {
        margin-top: 5px;
        .el-input__inner {
          height: 34px;
          line-height: 34px;
          padding-left: 8px;
        }
      }
      .radio_wrp {
        margin-top: 5px;
      }
      .el-checkbox__input.is-checked+.el-checkbox__label,
      .el-radio__input.is-checked+.el-radio__label {
        color: #606266;
      }
      .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner,
      .el-radio__input.is-checked .el-radio__inner {
        background-color: #4D7ED5;
        border-color: #4D7ED5;
      }
      .inner {
        .inner__items {
          &:not(:first-child) {
            margin-top: 5px;
          }
          &:after {
            content: '';
            clear: both;
            display: table;
          }
          > div {
            float: left;
            &:first-child {
              height: 34px;
              line-height: 43px;
              width: 15%;
              text-align: right;
            }
            &:last-child {
              padding-left: 10px;
              width: 85%;
            }
          }
        }
      }
      .table {
        width: 100%;
        border: 1px solid #e6e6e6;
        margin-top: 5px;
        .table_items {
          &:not(:first-child) {
            > div {
              border-top: 1px solid #e6e6e6;
            }
          }
          > div {
            float: left;
            height: 30px;
            line-height: 30px;
            text-align: center;
            position: relative;
            > input {
              border: 0;
              padding: 0 5px;
              position: absolute;
              top: 1px;
              right: 1px;
              bottom: 1px;
              left: 1px;
              width: 100%;
              text-align: center;
            }
            &:not(:first-child) {
              border-left: 1px solid #e6e6e6;
            }
            &.w5 {
              width: 5%;
              cursor: pointer;
            }
            &.w15 {
              width: 15%;
            }
            &.w40 {
              width: 40%;
            }
            &.w45 {
              width: 45%;
            }
            &.w50 {
              width: 50%;
            }
            &.w55 {
              width: 55%;
            }
            &.w80 {
              width: 80%;
              p {
                display: -webkit-box;
                -webkit-line-clamp: 1;
                overflow: hidden;
                /* autoprefixer:off */
                -webkit-box-orient: vertical;
                /* autoprefixer:on */
              }
            }
          }
          &:after {
            content: '';
            clear: both;
            display: table;
          }
        }
      }
      &.func {
        position: relative;
        .el-input.el-input--suffix {
          .el-input__inner {
            padding-right: 60px;
          }
          .el-input__suffix {
            margin-right: 45px;
          }
        }
        .el-textarea.el-input--suffix {
          textarea {
            padding-right: 60px;
          }
          .el-input__suffix {
            margin-right: 45px;
          }
        }
        > .jeicon {
          position: absolute;
          top: 30px;
          right: 10px;
          color: #999999;
          cursor: pointer;
          &.jeicon-error-circle {
            right: 30px;
            top: 32px;
            font-size: 13px;
          }
          &:hover {
            color: #333333;
          }
        }
      }
    }
  }
</style>

<style lang="scss">
  .page__syssetting_dialog {
    .holder_dialog {
      .el-dialog__body {
        padding: 30px 20px !important;
      }
      .dialog_content {
        max-height: 60vh;
        overflow-y: auto;
        font-size: 16px;
        p {
          margin-top: 15px;
        }
        img {
          margin-top: 15px;
          margin: 0 auto;
          display: block;
        }
      }
      .btn_group {
        width: 100%;
        margin-top: 30px;
        text-align: center;
        > span {
          padding: 6px 12px;
          border-radius: 4px;
          cursor: pointer;
          border: 1px solid #386bd0;
          color: #ffffff;
          background: #386bd0;
          font-size: 12px;
          &:hover {
            background-color: #1a4c9c;
            border-color: #1a4c9c;
          }
        }
      }
    }
  }
</style>

<style lang="scss">
    .sys_btns {
      padding: 6px 12px;
      border-radius: 4px;
      cursor: pointer;
      background: #f4f4f4;
      border: 1px solid #dddddd;
      color: #444444;
      font-size: 12px;
      display: inline-block;
      margin-top: 5px;
      &:not(:first-child) {
        margin-left: 10px;
      }
      > i {
        position: relative;
        top: 2px;
      }
      &:hover {
        background-color: #e7e7e7;
        border-color: #adadad;
      }
    }
</style>
